<template>
	<view style="padding: 30rpx;">
		<u-form label-width="160rpx">
			<u-form-item label="旧密码"><u-input type="password" placeholder="请输入旧密码" v-model="form.OldPassword"></u-input></u-form-item>
			<u-form-item label="新密码"><u-input type="password" placeholder="请输入新密码" v-model="form.NewPassword"></u-input></u-form-item>
			<u-form-item label="确认密码"><u-input type="password" placeholder="请再次输入新密码" v-model="ConfirmPassword"></u-input></u-form-item>

			<view class="u-text-right"><text @click="toForgotPasswordPage" class="u-font-12" style="color: #2979FF;">忘记密码</text></view>

			<view style="margin-top: 40rpx;"><u-button @tap="submit" type="warning">确认修改</u-button></view>
		</u-form>
	</view>
</template>

<script>
export default {
	data() {
		return {
			form: {
				OldPassword: '',
				NewPassword: ''
			},

			ConfirmPassword: ''
		};
	},

	methods: {
		toForgotPasswordPage() {
			this.$u.route({
				url: '/pages/personal/forgotPassword'
			});
		},

		submit() {
			if (!this.form.OldPassword) {
				this.$u.toast('请输入旧密码');
				return false;
			}

			if (!this.form.NewPassword) {
				this.$u.toast('请输入新密码');
				return false;
			}

			if (this.ConfirmPassword != this.form.NewPassword) {
				this.$u.toast('两次输入的密码不一致, 请重新输入');
				return false;
			}

			console.log(this.form);

			this.$u.api.updatePassword(this.form).then(res => {
				const { ResultCode, ResultMessage } = res;
				if (ResultCode == 1) {
					this.$u.toast(ResultMessage);
					setTimeout(() => {
						uni.navigateBack()
					}, 1000)
				}
			});
		}
	}
};
</script>

<style lang="scss"></style>
